package com.example.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Utils {
    public static String listToString(List idList) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < idList.size(); i++) {
            builder.append(idList.get(i))
                    .append(i == (idList.size() - 1) ? "" : ",");
        }
        System.out.println("字符串：" + builder.toString());
        return builder.toString();
    }

    public static List stringToList(String roles) {
        if (roles == null){
            return new ArrayList();
        }
        String[] split = roles.split(",");

        return new ArrayList(Arrays.asList(split));
    }

    public static void main(String[] args) {
        String s = "3,2";
        List list = stringToList(s);
        list.add(2);
        System.out.println(list);
    }
}
